package com.hzcx.app.simplechat.model;

import android.content.Context;

import com.hzcx.app.simplechat.api.APIRequest;
import com.hzcx.app.simplechat.api.BaseObserver;
import com.hzcx.app.simplechat.api.RxHelper;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.ui.user.bean.CityListBean;
import com.hzcx.app.simplechat.ui.user.bean.UserInfoBean;
import com.hzcx.app.simplechat.util.token.TokenUtils;

import java.util.List;

/**
 * 用户信息相关
 */
public class UserModel {

    /**
     * 首次登陆，添加用户资料
     *
     * @param context
     * @param avatar
     * @param nickname
     * @param observer
     */
    public static void updateUserInfo(Context context, String token, String avatar, String nickname, BaseObserver<BaseEmptyBean> observer) {
        updateUserInfo(context, token, avatar, nickname, null, null, null, null, null, null, null, observer);
    }

    /**
     * 修改用户背景墙
     *
     * @param context
     * @param backimage
     * @param observer
     */
    public static void updateUserBackImg(Context context, String backimage, BaseObserver<BaseEmptyBean> observer) {
        updateUserInfo(context, TokenUtils.getTokenHeader(), null, null, null, null, null, null, null, null, backimage, observer);
    }


    /**
     * 上传或修改用户资料
     *
     * @param context
     * @param avatar
     * @param nickname
     * @param chatnumber
     * @param gender
     * @param birthday
     * @param area
     * @param bio
     * @param observer
     */
    public static void updateUserInfo(Context context, String token, String avatar, String nickname, String chatnumber, String gender, String birthday,
                                      String area, String area_id, String bio, String backimage, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .updateUserInfo(token, avatar, nickname, chatnumber, gender, birthday, area, area_id, bio, backimage)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 获取用户详细资料
     *
     * @param context
     * @param id
     * @param observer
     */
    public static void getUserInfo(Context context, int id, BaseObserver<UserInfoBean> observer) {
        APIRequest
                .getRequestInterface()
                .getUserInfo(TokenUtils.getTokenHeader(), id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 设置好友备注跟描述
     *
     * @param context
     * @param member_id
     * @param remarks_name
     * @param description
     */
    public static void setUserRemarkName(Context context, int member_id, String remarks_name, String description, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .setUserRemarkName(TokenUtils.getTokenHeader(), member_id, remarks_name, description)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 把用户加入黑名单
     *
     * @param context
     * @param id
     * @param observer
     */
    public static void putUserInBlack(Context context, int id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .putUserInBlack(TokenUtils.getTokenHeader(), id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 把用户移除黑名单
     *
     * @param context
     * @param id
     * @param observer
     */
    public static void putUserOutBlack(Context context, int id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .putUserOutBlack(TokenUtils.getTokenHeader(), id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 获取城市列表
     *
     * @param context
     * @param observer
     */
    public static void getCityList(Context context, BaseObserver<List<CityListBean>> observer) {
        APIRequest
                .getRequestInterface()
                .getCityList(TokenUtils.getTokenHeader())
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 根据二维码获取用户信息
     *
     * @param context
     * @param url
     * @param observer
     */
    public static void getUserInfoByQrCode(Context context, String url, BaseObserver<UserInfoBean> observer) {
        APIRequest
                .getRequestInterface()
                .getUserInfoByQrCode(url, TokenUtils.getTokenHeader())
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     *  设置好友标签
     * @param context
     * @param member_id
     * @param lable_name
     * @param observer
     */
    public static void setUserLable(Context context, int member_id, String lable_name, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .setUserLable(TokenUtils.getTokenHeader(), member_id, lable_name)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }
}
